<?php

namespace App\Http\Controllers;

use App\Services\NovelService;

class NovelController extends Controller
{
    public function getNovelDetail(NovelService $novelService)
    {
        $detail = $novelService->getNovelDetail($this->requests['novel_id'] ?? null, $this->userId);
        return renderSuccessJson($detail);
    }

    public function read(NovelService $novelService)
    {
        $novelId = $this->requests['novel_id'] ?? null;
        $orderNum = $this->requests['order_num'] ?? null;
        $isPay = $this->requests['is_pay'] ?? 'N';
        $chapterResult = $novelService->getChanpterContent($novelId, $orderNum, $this->userId, $isPay);
        return renderSuccessJson($chapterResult);
    }

    public function getChapterList(NovelService $novelService)
    {
        $lists = $novelService->getChapterList($this->requests['novel_id'], $this->userId);
        return renderSuccessJson($lists);
    }

    public function search(NovelService $novelService)
    {
        $searchResult = $novelService->searchNovel($this->requests['search'] ?? null);
        return renderSuccessJson($searchResult);
    }

    public function getRandomRec(NovelService $novelService)
    {
        $random = $novelService->getRandomRec();
        return renderSuccessJson($random);
    }

    public function getAllTag(NovelService $novelService)
    {
        $tags = $novelService->getAllNovelTags();
        return renderSuccessJson($tags);
    }

    public function getNovelsByTag(NovelService $novelService)
    {
        $tagId = $this->requests['tag_id'] ?? null;
        $novels = $novelService->getNovelsByTag($tagId);
        return renderSuccessJson($novels);
    }
}
